package com.ycl.bookstore.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.ycl.bookstore.utils.RabbitMqConstants.*;

@Configuration
public class RabbitMqConfig {

    @Value(FRIENDS_LIKE_EXCHANGE)
    private String likeExchange;
    @Value(FRIENDS_LIKE_QUEUE)
    private String likeQueue;

    // 定义交换机
    @Bean
    public DirectExchange likeExchange(){
        return ExchangeBuilder.directExchange(likeExchange).build();
    }

    //定义队列
    @Bean
    public Queue likeQueue(){
        return QueueBuilder.durable(likeQueue).build();
    }

    // 绑定交换机和队列
    @Bean
    public Binding binding(Queue likeQueue,DirectExchange likeExchange){
        return BindingBuilder.bind(likeQueue).to(likeExchange).with(FRIENDS_LIKE_ROUTINGKEY);
    }
}
